<?php echo $this->element('displayHeader'); ?>
<div class="toolbar"><?php echo $this->element('toolbar', array('buttons' => array(array('refresh' => array('action' => 'cust_stock_out_cost_center_search'))))); ?></div>

<?php echo $form->create(null, array('id' => 'frmSearch', 'action' => 'cust_stock_out_cost_center', 'target' => '_blank')); ?>
<fieldset>
    <legend>Criteria</legend>
    <table>
        <tr>
            <td width="120px"><?php echo $form->label('CustProductSite.customer_id', 'Customer', array('class' => 'required')); ?></td>
            <td width="250px"><?php echo $form->select('CustProductSite.customer_id', $customers, null, null, OPTION_ALL); ?></td>
            <td width="100px"><?php echo $form->label('CustStockOutHead.site_cost_center_id', 'Cost Center'); ?></td>
            <td><?php echo $form->select('CustStockOutHead.site_cost_center_id', null, null, null, OPTION_ALL); ?></td>
        </tr>
        <tr>
            <td><?php echo $form->label('CustProductSite.site_id', 'Site', array('class' => 'required')); ?></td>
            <td><?php echo $form->select('CustProductSite.site_id', null, null, null, OPTION_ALL); ?></td>
            <td colspan="2">
                <?php echo $form->hidden('CustStockOutHead.dispatch_from', array('value' => SUPPLIER_PREFIX)); ?>
                <?php echo $form->hidden('CustStockOutHead.supplier_id', array('value' => $session->read('Auth.User.supplier_id'))); ?>
            </td>
        </tr>
        <tr>
            <td colspan="4"><hr /></td>
        </tr>
        <tr>
            <td class="top"><?php echo $form->label('CustStockOutHead.stock_out_date', 'Stock out Date'); ?></td>
            <td>
                From <?php echo $form->text('CustStockOutHead.stock_out_date_start', array('size' => 7, 'class' => 'text-right')); ?>
                To <?php echo $form->text('CustStockOutHead.stock_out_date_end', array('size' => 7, 'class' => 'text-right')); ?>
            </td>
        </tr>
        <tr>
            <td colspan="4"><hr /></td>
        </tr>
    </table>
    <table>
        <tr>
            <td class="top" width="150px"><?php echo $form->label('display', 'Additional Information'); ?></td>
            <td>
                <?php echo $form->checkbox('Option.display_stock_out_no'); ?>&nbsp;&nbsp;Stock out no. / Stock out date/ Remark / Product Description
            </td>
        </tr>
    </table>
    <?php echo $this->element('report/buttons', array('action' => 'stock_out', 'button' => array('search', 'print', 'excel'))); ?>
            </fieldset>
<?php echo $form->end(); ?>

                <script type="text/javascript">
                    $j(function() {
                        $j.datesearchpicker("#CustStockOutHeadStockOutDate");
                        $j(':radio[id^=CustStockOutHeadDispatchFrom]').bind('click', function() {
                            var dispatch_from = $j(this).val();
                            if (dispatch_from == SUPPLIER_PREFIX) {
                                $j('#CustStockOutHeadSupplierId').show();
                                // ถ้าเลือก ITS หรือ All
                            } else {
                                $j('#CustStockOutHeadSupplierId').hide().val('');
                                // Request option ของ ITS กลับมาใส่ใหม่
                                $j('#ProductBrandId').requestOptions('cust_product_sites/option_its_brand_list', null, {empty_option: '--All--'});
                            }
                        });

                        $j('button').handover();

                        $j('#CustProductSiteCustomerId').bind('change', function() {
                            $j('#CustProductSiteSiteId').requestOptions('sites/option_list', $j(this).val(), {empty_option: '--All--'});
                            $j('#CustStockOutHeadSiteCostCenterId').empty();
                        }).val('');

                        $j('#CustProductSiteSiteId').bind('change', function() {
                            $j('#CustStockOutHeadSiteCostCenterId').requestOptions('sites/option_list_cost_center', $j(this).val(), {empty_option: '--All--'});
                        }).val('');

                        $j(':input').bind('keypress', stopKeyEnter);
                    });

                    // ดักจับ event ก่อนการ search, print และ excel
                    beforeSearch = function() {
                        // ยังไม่ได้เลือก Customer
                        if ($j('#CustProductSiteCustomerId').val() == '') {
                            alert('Please select a customer first.!');
                            return false;
                        }

                        // ยังไม่ได้เลือก Site
                        if ($j('#CustProductSiteSiteId').val() == '') {
                            alert('Please select a customer site first.!');
                            return false;
                        }
                        return true;
                    }
                </script>
<?php echo $this->element('report/result'); ?>
